using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_VKPOS
    {
        public DataRow Convert2QVW_VKPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_VKPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["MANDANT"] = " ".PadRight(2 ); 
         dwReturn["VKKVB"] = " ".PadRight(3 ); 
         dwReturn["VKKVG"] = " ".PadRight(3 ); 
         dwReturn["NYEAR"] = " ".PadRight(4 ); 
         dwReturn["NMONTH"] = " ".PadRight(2 ); 
         dwReturn["NDAY"] = " ".PadRight(2 ); 
         dwReturn["NQUARTER"] = " ".PadRight(41 ); 
         dwReturn["VKKAUF"] = " ".PadRight(9 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["VKPAUF"] = " ".PadRight(12 ); 
         dwReturn["VKPAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VKPAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VKPAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VKPNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["VKPNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["KDNR"] = " ".PadRight(8 ); 
         dwReturn["VKPSACHBE"] = " ".PadRight(8 ); 
         dwReturn["VKPPOSTYP"] = " ".PadRight(3 ); 
         dwReturn["ARTST"] = " ".PadRight(1 ); 
         dwReturn["VKPKOLL"] = " ".PadRight(5 ); 
         dwReturn["VKPART"] = " ".PadRight(24 ); 
         dwReturn["VKPFARBE"] = " ".PadRight(10 ); 
         dwReturn["VKPGROE"] = " ".PadRight(7 ); 
         dwReturn["VART"] = " ".PadRight(29 ); 
         dwReturn["VFARBE"] = " ".PadRight(39 ); 
         dwReturn["VASKU"] = " ".PadRight(46 ); 
         dwReturn["PRGR"] = " ".PadRight(3 ); 
         dwReturn["ARTGRP"] = " ".PadRight(3 ); 
         dwReturn["VKPMEEH"] = " ".PadRight(3 ); 
         dwReturn["VKPPREH"] = " ".PadRight(3 ); 
         dwReturn["VKPPREIS"] = " ".PadRight(0 ); 
         dwReturn["PFCOST"] = " ".PadRight(0 ); 
         dwReturn["GPROFIT"] = " ".PadRight(0 ); 
         dwReturn["EXCHANGERATE"] = " ".PadRight(0 ); 
         dwReturn["VKPVALUE"] = " ".PadRight(0 ); 
         dwReturn["VKPQTY"] = " ".PadRight(0 ); 
         dwReturn["VKPRESERV"] = " ".PadRight(0 ); 
         dwReturn["VKPZUGET"] = " ".PadRight(0 ); 
         dwReturn["VKPFREIGE"] = " ".PadRight(0 ); 
         dwReturn["VKPKOMMISS"] = " ".PadRight(0 ); 
         dwReturn["VKPVERS"] = " ".PadRight(0 ); 
         dwReturn["VKPFAKT"] = " ".PadRight(0 ); 
         dwReturn["SYEAR"] = " ".PadRight(4 ); 
         dwReturn["SMONTH"] = " ".PadRight(2 ); 
         dwReturn["SDAY"] = " ".PadRight(2 ); 
         dwReturn["SQUARTER"] = " ".PadRight(41 ); 
         dwReturn["DYEAR"] = " ".PadRight(4 ); 
         dwReturn["DMONTH"] = " ".PadRight(2 ); 
         dwReturn["DDAY"] = " ".PadRight(2 ); 
         dwReturn["DQUARTER"] = " ".PadRight(41 ); 
         dwReturn["FYEAR"] = " ".PadRight(4 ); 
         dwReturn["FMONTH"] = " ".PadRight(2 ); 
         dwReturn["FDAY"] = " ".PadRight(2 ); 
         dwReturn["FQUARTER"] = " ".PadRight(41 ); 
         dwReturn["VYEAR"] = " ".PadRight(4 ); 
         dwReturn["VMONTH"] = " ".PadRight(2 ); 
         dwReturn["VDAY"] = " ".PadRight(2 ); 
         dwReturn["VQUARTER"] = " ".PadRight(41 ); 
         dwReturn["VKPWVTERM"] = " ".PadRight(0 ); 
         dwReturn["VKPWUTERM"] = " ".PadRight(0 ); 
         dwReturn["VKPFREITERM"] = " ".PadRight(0 ); 
         dwReturn["VKPVERSTERM"] = " ".PadRight(0 ); 
         dwReturn["VKPLIEFTERM"] = " ".PadRight(0 ); 
         dwReturn["VKPFRDAT"] = " ".PadRight(0 ); 
         dwReturn["VKPZKDAT"] = " ".PadRight(0 ); 
         dwReturn["VKPLVDAT"] = " ".PadRight(0 ); 
         dwReturn["VKPERL"] = " ".PadRight(1 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_VKPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_VKPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_VKPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_VKPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_VKPOS(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_VKPOS(dwLocal);
        }
        public void InsertQVW_VKPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_VKPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_VKPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_VKPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_VKPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_VKPOS";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_VKPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_VKPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_VKPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_VKPOS SET "
                    +"MANDANT= :MANDANT,"
                    +"VKKVB= :VKKVB,"
                    +"VKKVG= :VKKVG,"
                    +"NYEAR= :NYEAR,"
                    +"NMONTH= :NMONTH,"
                    +"NDAY= :NDAY,"
                    +"NQUARTER= :NQUARTER,"
                    +"VKKAUF= :VKKAUF,"
                    +"AUFTYP= :AUFTYP,"
                    +"VKPAUF= :VKPAUF,"
                    +"VKPAUFKRS= :VKPAUFKRS,"
                    +"VKPAUFLFD= :VKPAUFLFD,"
                    +"VKPAUFPOS= :VKPAUFPOS,"
                    +"VKPNEUDAT= :VKPNEUDAT,"
                    +"VKPNEUBEN= :VKPNEUBEN,"
                    +"KDNR= :KDNR,"
                    +"VKPSACHBE= :VKPSACHBE,"
                    +"VKPPOSTYP= :VKPPOSTYP,"
                    +"ARTST= :ARTST,"
                    +"VKPKOLL= :VKPKOLL,"
                    +"VKPART= :VKPART,"
                    +"VKPFARBE= :VKPFARBE,"
                    +"VKPGROE= :VKPGROE,"
                    +"VART= :VART,"
                    +"VFARBE= :VFARBE,"
                    +"VASKU= :VASKU,"
                    +"PRGR= :PRGR,"
                    +"ARTGRP= :ARTGRP,"
                    +"VKPMEEH= :VKPMEEH,"
                    +"VKPPREH= :VKPPREH,"
                    +"VKPPREIS= :VKPPREIS,"
                    +"PFCOST= :PFCOST,"
                    +"GPROFIT= :GPROFIT,"
                    +"EXCHANGERATE= :EXCHANGERATE,"
                    +"VKPVALUE= :VKPVALUE,"
                    +"VKPQTY= :VKPQTY,"
                    +"VKPRESERV= :VKPRESERV,"
                    +"VKPZUGET= :VKPZUGET,"
                    +"VKPFREIGE= :VKPFREIGE,"
                    +"VKPKOMMISS= :VKPKOMMISS,"
                    +"VKPVERS= :VKPVERS,"
                    +"VKPFAKT= :VKPFAKT,"
                    +"SYEAR= :SYEAR,"
                    +"SMONTH= :SMONTH,"
                    +"SDAY= :SDAY,"
                    +"SQUARTER= :SQUARTER,"
                    +"DYEAR= :DYEAR,"
                    +"DMONTH= :DMONTH,"
                    +"DDAY= :DDAY,"
                    +"DQUARTER= :DQUARTER,"
                    +"FYEAR= :FYEAR,"
                    +"FMONTH= :FMONTH,"
                    +"FDAY= :FDAY,"
                    +"FQUARTER= :FQUARTER,"
                    +"VYEAR= :VYEAR,"
                    +"VMONTH= :VMONTH,"
                    +"VDAY= :VDAY,"
                    +"VQUARTER= :VQUARTER,"
                    +"VKPWVTERM= :VKPWVTERM,"
                    +"VKPWUTERM= :VKPWUTERM,"
                    +"VKPFREITERM= :VKPFREITERM,"
                    +"VKPVERSTERM= :VKPVERSTERM,"
                    +"VKPLIEFTERM= :VKPLIEFTERM,"
                    +"VKPFRDAT= :VKPFRDAT,"
                    +"VKPZKDAT= :VKPZKDAT,"
                    +"VKPLVDAT= :VKPLVDAT,"
                    +"VKPERL= :VKPERL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString(); 
          or1.Parameters.Add("VKKVB", OracleType.NVarChar).Value = dwData["VKKVB"].ToString(); 
          or1.Parameters.Add("VKKVG", OracleType.NVarChar).Value = dwData["VKKVG"].ToString(); 
          or1.Parameters.Add("NYEAR", OracleType.NVarChar).Value = dwData["NYEAR"].ToString(); 
          or1.Parameters.Add("NMONTH", OracleType.NVarChar).Value = dwData["NMONTH"].ToString(); 
          or1.Parameters.Add("NDAY", OracleType.NVarChar).Value = dwData["NDAY"].ToString(); 
          or1.Parameters.Add("NQUARTER", OracleType.NVarChar).Value = dwData["NQUARTER"].ToString(); 
          or1.Parameters.Add("VKKAUF", OracleType.NVarChar).Value = dwData["VKKAUF"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("VKPAUF", OracleType.NVarChar).Value = dwData["VKPAUF"].ToString(); 
          or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwData["VKPAUFKRS"].ToString(); 
          or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwData["VKPAUFLFD"].ToString(); 
          or1.Parameters.Add("VKPAUFPOS", OracleType.NVarChar).Value = dwData["VKPAUFPOS"].ToString(); 
          or1.Parameters.Add("VKPNEUDAT", OracleType.NVarChar).Value = dwData["VKPNEUDAT"].ToString(); 
          or1.Parameters.Add("VKPNEUBEN", OracleType.NVarChar).Value = dwData["VKPNEUBEN"].ToString(); 
          or1.Parameters.Add("KDNR", OracleType.NVarChar).Value = dwData["KDNR"].ToString(); 
          or1.Parameters.Add("VKPSACHBE", OracleType.NVarChar).Value = dwData["VKPSACHBE"].ToString(); 
          or1.Parameters.Add("VKPPOSTYP", OracleType.NVarChar).Value = dwData["VKPPOSTYP"].ToString(); 
          or1.Parameters.Add("ARTST", OracleType.NVarChar).Value = dwData["ARTST"].ToString(); 
          or1.Parameters.Add("VKPKOLL", OracleType.NVarChar).Value = dwData["VKPKOLL"].ToString(); 
          or1.Parameters.Add("VKPART", OracleType.NVarChar).Value = dwData["VKPART"].ToString(); 
          or1.Parameters.Add("VKPFARBE", OracleType.NVarChar).Value = dwData["VKPFARBE"].ToString(); 
          or1.Parameters.Add("VKPGROE", OracleType.NVarChar).Value = dwData["VKPGROE"].ToString(); 
          or1.Parameters.Add("VART", OracleType.NVarChar).Value = dwData["VART"].ToString(); 
          or1.Parameters.Add("VFARBE", OracleType.NVarChar).Value = dwData["VFARBE"].ToString(); 
          or1.Parameters.Add("VASKU", OracleType.NVarChar).Value = dwData["VASKU"].ToString(); 
          or1.Parameters.Add("PRGR", OracleType.NVarChar).Value = dwData["PRGR"].ToString(); 
          or1.Parameters.Add("ARTGRP", OracleType.NVarChar).Value = dwData["ARTGRP"].ToString(); 
          or1.Parameters.Add("VKPMEEH", OracleType.NVarChar).Value = dwData["VKPMEEH"].ToString(); 
          or1.Parameters.Add("VKPPREH", OracleType.NVarChar).Value = dwData["VKPPREH"].ToString(); 
          or1.Parameters.Add("VKPPREIS", OracleType.NVarChar).Value = dwData["VKPPREIS"].ToString(); 
          or1.Parameters.Add("PFCOST", OracleType.NVarChar).Value = dwData["PFCOST"].ToString(); 
          or1.Parameters.Add("GPROFIT", OracleType.NVarChar).Value = dwData["GPROFIT"].ToString(); 
          or1.Parameters.Add("EXCHANGERATE", OracleType.NVarChar).Value = dwData["EXCHANGERATE"].ToString(); 
          or1.Parameters.Add("VKPVALUE", OracleType.NVarChar).Value = dwData["VKPVALUE"].ToString(); 
          or1.Parameters.Add("VKPQTY", OracleType.NVarChar).Value = dwData["VKPQTY"].ToString(); 
          or1.Parameters.Add("VKPRESERV", OracleType.NVarChar).Value = dwData["VKPRESERV"].ToString(); 
          or1.Parameters.Add("VKPZUGET", OracleType.NVarChar).Value = dwData["VKPZUGET"].ToString(); 
          or1.Parameters.Add("VKPFREIGE", OracleType.NVarChar).Value = dwData["VKPFREIGE"].ToString(); 
          or1.Parameters.Add("VKPKOMMISS", OracleType.NVarChar).Value = dwData["VKPKOMMISS"].ToString(); 
          or1.Parameters.Add("VKPVERS", OracleType.NVarChar).Value = dwData["VKPVERS"].ToString(); 
          or1.Parameters.Add("VKPFAKT", OracleType.NVarChar).Value = dwData["VKPFAKT"].ToString(); 
          or1.Parameters.Add("SYEAR", OracleType.NVarChar).Value = dwData["SYEAR"].ToString(); 
          or1.Parameters.Add("SMONTH", OracleType.NVarChar).Value = dwData["SMONTH"].ToString(); 
          or1.Parameters.Add("SDAY", OracleType.NVarChar).Value = dwData["SDAY"].ToString(); 
          or1.Parameters.Add("SQUARTER", OracleType.NVarChar).Value = dwData["SQUARTER"].ToString(); 
          or1.Parameters.Add("DYEAR", OracleType.NVarChar).Value = dwData["DYEAR"].ToString(); 
          or1.Parameters.Add("DMONTH", OracleType.NVarChar).Value = dwData["DMONTH"].ToString(); 
          or1.Parameters.Add("DDAY", OracleType.NVarChar).Value = dwData["DDAY"].ToString(); 
          or1.Parameters.Add("DQUARTER", OracleType.NVarChar).Value = dwData["DQUARTER"].ToString(); 
          or1.Parameters.Add("FYEAR", OracleType.NVarChar).Value = dwData["FYEAR"].ToString(); 
          or1.Parameters.Add("FMONTH", OracleType.NVarChar).Value = dwData["FMONTH"].ToString(); 
          or1.Parameters.Add("FDAY", OracleType.NVarChar).Value = dwData["FDAY"].ToString(); 
          or1.Parameters.Add("FQUARTER", OracleType.NVarChar).Value = dwData["FQUARTER"].ToString(); 
          or1.Parameters.Add("VYEAR", OracleType.NVarChar).Value = dwData["VYEAR"].ToString(); 
          or1.Parameters.Add("VMONTH", OracleType.NVarChar).Value = dwData["VMONTH"].ToString(); 
          or1.Parameters.Add("VDAY", OracleType.NVarChar).Value = dwData["VDAY"].ToString(); 
          or1.Parameters.Add("VQUARTER", OracleType.NVarChar).Value = dwData["VQUARTER"].ToString(); 
          or1.Parameters.Add("VKPWVTERM", OracleType.NVarChar).Value = dwData["VKPWVTERM"].ToString(); 
          or1.Parameters.Add("VKPWUTERM", OracleType.NVarChar).Value = dwData["VKPWUTERM"].ToString(); 
          or1.Parameters.Add("VKPFREITERM", OracleType.NVarChar).Value = dwData["VKPFREITERM"].ToString(); 
          or1.Parameters.Add("VKPVERSTERM", OracleType.NVarChar).Value = dwData["VKPVERSTERM"].ToString(); 
          or1.Parameters.Add("VKPLIEFTERM", OracleType.NVarChar).Value = dwData["VKPLIEFTERM"].ToString(); 
          or1.Parameters.Add("VKPFRDAT", OracleType.NVarChar).Value = dwData["VKPFRDAT"].ToString(); 
          or1.Parameters.Add("VKPZKDAT", OracleType.NVarChar).Value = dwData["VKPZKDAT"].ToString(); 
          or1.Parameters.Add("VKPLVDAT", OracleType.NVarChar).Value = dwData["VKPLVDAT"].ToString(); 
          or1.Parameters.Add("VKPERL", OracleType.NVarChar).Value = dwData["VKPERL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
